package cn.stylefeng.guns.modular.vlt.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.vlt.entity.Active;
import cn.stylefeng.guns.modular.vlt.mapper.ActiveMapper;
import cn.stylefeng.guns.modular.vlt.model.params.ActiveParam;
import cn.stylefeng.guns.modular.vlt.model.result.ActiveResult;
import  cn.stylefeng.guns.modular.vlt.service.ActiveService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 志愿活动信息表 服务实现类
 * </p>
 *
 * @author 
 * @since 2020-12-16
 */
@Service
public class ActiveServiceImpl extends ServiceImpl<ActiveMapper, Active> implements ActiveService {

    @Override
    public void add(ActiveParam param){
        Active entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(ActiveParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(ActiveParam param){
        Active oldEntity = getOldEntity(param);
        Active newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public ActiveResult findBySpec(ActiveParam param){
        return null;
    }

    @Override
    public List<ActiveResult> findListBySpec(ActiveParam param){
        return null;
    }

    @Override
    public List<ActiveResult> cntA() {
        return this.baseMapper.cntA();
    }

    @Override
    public LayuiPageInfo findPageBySpec(ActiveParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(ActiveParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private Active getOldEntity(ActiveParam param) {
        return this.getById(getKey(param));
    }

    private Active getEntity(ActiveParam param) {
        Active entity = new Active();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
